<?php
include_once 'inc/config.inc.php';
include_once 'inc/mysql.inc.php';
include_once 'inc/tool.inc.php';
$link=connect();
if(!$member_id=is_login($link)){
    skip($_SERVER["HTTP_REFERER"], 'error', '请登录之后再做回复!');
}
if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
    skip($_SERVER["HTTP_REFERER"], 'error', '您要回复的帖子id参数不合法!');
}
// 回复信息处理
if(isset($_POST['submit'])) {
    if (mb_strlen($_POST['content']) < 3) {
        skip($_SERVER["HTTP_REFERER"],'error','回复信息字符不能少于3个字');
    }
    // 存储回复信息
    $_POST=escape($link,$_POST);
    $query="insert into sfk_reply(content_id,content,time,member_id) values({$_GET['id']},'{$_POST['content']}',now(),{$member_id})";
    execute($link, $query);
    if($link->affected_rows == 1) {
        // 更新帖子最新回复时间
        $query = "UPDATE sfk_content SET new_time = NOW() WHERE id = {$_GET['id']}
";
        execute($link,$query);
        skip("show.php?id={$_GET['id']}", 'ok', '回复成功!');
    }else{
        skip($_SERVER['REQUEST_URI'], 'error', '回复失败,请重试!');
    }
}
$template['title']='帖子回复页';
$template['css']=array('style/public.css','style/publish.css');

?>
<?php include 'inc/header.inc.php'?>
<div id="position" class="auto">
    <a href="<?=$_SERVER["HTTP_REFERER"]?>">返回上一页</a> &gt; 回复帖子
</div>
<?php
$query = "SELECT c.title,c.content,s.name from sfk_content c LEFT JOIN sfk_member s on  c.member_id = s.id where c.id = {$_GET['id']} LIMIT 1";
$data_content = execute($link,$query);
if($data_content->num_rows != 1){
    skip($_SERVER["HTTP_REFERER"], 'error', '您要回复的帖子不存在!');
}
$data_content = $data_content->fetch_assoc();
$data_content['title']=htmlspecialchars($data_content['title']);
$data_content['content']=nl2br(htmlspecialchars($data_content['content']));
?>
<div id="publish">
    <div>回复由<?=$data_content['name']?>发布的：<?=$data_content['title']?><br>
        内容：<?=$data_content['content']?>
    </div>
    <form method="post">
        <textarea name="content" class="content"></textarea>
        <input class="reply" type="submit" name="submit" value="" />
        <div style="clear:both;"></div>
    </form>
</div>
<?php include 'inc/footer.inc.php'?>
